package com.liu.shop.config;


import com.liu.shop.interceptor.LoginInterceptor;
import com.liu.shop.interceptor.OrderDynamicDatasourceInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private OrderDynamicDatasourceInterceptor orderDynamicDatasourceInterceptor;

    /**
     * 设置优先级，数字越小优先级越高,忽略更新订单的请求，不会走拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .excludePathPatterns("/order/updateOrderStatus")
                .addPathPatterns("/**").
                order(1);
        registry.addInterceptor(orderDynamicDatasourceInterceptor)
                .excludePathPatterns("/order/updateOrderStatus")
                .addPathPatterns("/**").order(2);
    }
}
